package com.xuecheng.system.init;

import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ResourceLoader;

import java.util.Arrays;
import java.util.Set;

/**
 * Created on 2021/04/07/0:14 周三
 *
 * @author Lantin
 */
public class MyClassPathPkgScanner extends ClassPathBeanDefinitionScanner {
    public MyClassPathPkgScanner(BeanDefinitionRegistry registry) {
        super(registry);
    }

    public MyClassPathPkgScanner(BeanDefinitionRegistry registry, boolean useDefaultFilters) {
        super(registry, useDefaultFilters);
    }

    public MyClassPathPkgScanner(BeanDefinitionRegistry registry, boolean useDefaultFilters, Environment environment) {
        super(registry, useDefaultFilters, environment);
    }

    public MyClassPathPkgScanner(BeanDefinitionRegistry registry, boolean useDefaultFilters, Environment environment, ResourceLoader resourceLoader) {
        super(registry, useDefaultFilters, environment, resourceLoader);
    }

    @Override
    protected Set<BeanDefinitionHolder> doScan(String... basePackages) {
        Set<BeanDefinitionHolder> beanDefinitions = super.doScan(basePackages);

        if (beanDefinitions.isEmpty()) {
            logger.warn("No DgbSecurity Spring Componet was found in '" + Arrays.toString(basePackages) + "' package. Please check your configuration.");
        }
        System.out.println("EnumScan获得的BeanName为");
        for (BeanDefinitionHolder beanDefinition : beanDefinitions) {

            System.out.println(beanDefinition.getBeanName());
        }
        System.out.println("EnumScan获得的BeanName结束");
        return beanDefinitions;
    }
}
